import router from '@/router'
import { Message } from 'element-ui'
export default {
    install: (Vue) => {
        Vue.mixin({
            beforeCreate() {
                if (this.$options.authorize) {
                    const authorize = this.$options.authorize
                    const permission = router.history.current.meta.permission || []
                    // if (permission.length > 0) {
                        Object.keys(authorize).forEach(key => {
                            const method = this.$options.methods[key]
                            if (typeof method === 'function' && permission.indexOf(authorize[key]) == -1) {
                                // router meta permission  没有该权限时函数切换成没有该权限
                                this.$options.methods[key] = function () {
                                    Message({
                                        message: `对不起，您没有操作权限：${authorize[key]}`,
                                        type: 'error',
                                        duration:2000
                                    })
                                }
                            }
                        })
                    // }
                }
            },
        })
    }
}